<html>
	<head>
	<meta charset="utf-8">
	<title>\获取jskeycode\</title>
	</head>

	<body>
		<div>
			此文件需在电脑上运行，哪个键按下就显示它对应的jskeycode,刚按的显示在最上边：<br>
			<div id="jskeycode">
			</div>
			<br><br>
			ascii码表(跟jskeycode没关系，只是显示在这里)：<br>
			<div id="ascii">
			</div>
		</div>
		<br><br>
	</body>
</html>

<script>
	window.onkeydown = function(e) { 
		doKeyDown(e);
		return false;
	};

	function doKeyDown(e) {
		var keyID = e.keyCode ? e.keyCode :e.which;

		var view = document.getElementById("jskeycode");
		if(116 == keyID) {
			view.innerHTML =  "按键jskeycode: " + keyID + "　　F5键已被拦截，请用鼠标刷新网页<br>\n" + view.innerHTML;
		}else{
			view.innerHTML =  "按键jskeycode: " + keyID + "<br>\n" + view.innerHTML;
		}
	}

	function isTerminalChar(c)
	{
		var tc1 = "0123456789";
		var tc2 = "abcdefghijklmnopqrstuvwxyz";
		var tc3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		var tc4 = " `~!@#$%^&*()-=_+[]\\{}|;':\",./<>?";

		var i=0;
		for(i=0; i< tc1.length; i++) if(c == tc1[i]) return 1;
		for(i=0; i< tc2.length; i++) if(c == tc2[i]) return 1;
		for(i=0; i< tc3.length; i++) if(c == tc3[i]) return 1;
		for(i=0; i< tc4.length; i++) if(c == tc4[i]) return 1;

		return 0;
	}

	function dumpAscii() {
		var view = document.getElementById("ascii");
		for(var i=0;i<256;i++){
		
			var c   = String.fromCharCode(i);
			var str = '';
			
			if(isTerminalChar(c)) {
				if(c=='"') {
					str = '{.name_on_the_keyboard = "双引号",		.ucs4_code ='+i+', .ucs4_char = \'\\"\' },';
				}else{
					str = '{.name_on_the_keyboard = "btn_'+c+'",	.ucs4_code ='+i+', .ucs4_char = \''+c+'\' },';
				}
			}else{
				if(c=='\0') {
					str = '{.name_on_the_keyboard = "ucs4_null",	.ucs4_code ='+i+', .ucs4_char = \'\\0\' },';
				}else if(c=='\r') {
					str = '{.name_on_the_keyboard = "btn_return",	.ucs4_code ='+i+', .ucs4_char = \'\\r\' },';
				}else if(c=='\n') {
					str = '{.name_on_the_keyboard = "btn_enter",	.ucs4_code ='+i+', .ucs4_char = \'\\n\' },';
				}else if(c=='\t') {
					str = '{.name_on_the_keyboard = "btn_tab",		.ucs4_code ='+i+', .ucs4_char = \'\\t\' },';
				}else if(c=='\b') {
					str = '{.name_on_the_keyboard = "btn_back",		.ucs4_code ='+i+', .ucs4_char = \'\\b\' },';
				}else{
					str = '{.name_on_the_keyboard = "btn_'+i+'",	.ucs4_code ='+i+', .ucs4_char = \'.\' },';
				}
			}
			view.innerHTML +=  str + "<br>\n";
		}
	}

	dumpAscii();

</script>
